package com.platform.controller.platform;

import com.platform.common.annotation.Log;
import com.platform.common.core.domain.AjaxResult;
import com.platform.common.core.page.TableDataInfo;
import com.platform.common.enums.BusinessType;
import com.platform.common.enums.ResultEnum;
import com.platform.common.exception.BusinessException;
import com.platform.system.domain.dto.device.ChatBackgroundMusicDto;
import com.platform.system.domain.dto.device.SpeakerInfoDto;
import com.platform.system.domain.vo.device.ChatBackgroundMusicVo;
import com.platform.system.domain.vo.device.SpeakerInfoVo;
import com.platform.system.service.ISysChatBackgroundMusicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Huangkai
 */
@Slf4j
@RestController
@RequestMapping("/speaker/chatBackgroundMusic")
public class ChatBackgroundMusicController {

    @Resource
    ISysChatBackgroundMusicService sysChatBackgroundMusicService;

    /**
     * 查询发音人
     */
    @Log(title = "查询新增聊天背景音乐", businessType = BusinessType.OTHER)
    @GetMapping("/selectChatBackgroundMusicList")
    public TableDataInfo selectChatBackgroundMusicList(@Validated ChatBackgroundMusicVo chatBackgroundMusicVo) {
        return sysChatBackgroundMusicService.selectChatBackgroundMusicList(chatBackgroundMusicVo);
    }

    @Log(title = "查询新增聊天背景音乐详情", businessType = BusinessType.OTHER)
    @GetMapping("/selectChatBackgroundMusic/{uid}")
    public AjaxResult selectChatBackgroundMusic(@PathVariable(value = "uid") String uid) {
        ChatBackgroundMusicDto chatBackgroundMusicDto = sysChatBackgroundMusicService.selectChatBackgroundMusic(uid);
        if(chatBackgroundMusicDto == null){
            throw new BusinessException(ResultEnum.DATA_NOT_EXIST);
        }
        return AjaxResult.success(chatBackgroundMusicDto);
    }

    /**
     * 新增
     */
    @Log(title = "新增聊天背景音乐", businessType = BusinessType.INSERT)
    @PostMapping("/insertChatBackgroundMusic")
    public AjaxResult insertChatBackgroundMusic(@RequestBody @Validated ChatBackgroundMusicVo chatBackgroundMusicVo) {
        return sysChatBackgroundMusicService.insertChatBackgroundMusic(chatBackgroundMusicVo);
    }

    /**
     * 修改
     */
    @Log(title = "修改聊天背景音乐", businessType = BusinessType.UPDATE)
    @PostMapping("/updateChatBackgroundMusic")
    public AjaxResult updateChatBackgroundMusic(@RequestBody @Validated ChatBackgroundMusicVo chatBackgroundMusicVo) {
        return sysChatBackgroundMusicService.updateChatBackgroundMusic(chatBackgroundMusicVo);
    }

    /**
     * 删除
     */
    @Log(title = "删除聊天背景音乐", businessType = BusinessType.DELETE)
    @PostMapping("/deleteChatBackgroundMusic")
    public AjaxResult deleteChatBackgroundMusic(@RequestBody @Validated ChatBackgroundMusicVo chatBackgroundMusicVo) {
        return sysChatBackgroundMusicService.deleteChatBackgroundMusic(chatBackgroundMusicVo);
    }

}
